package com.zhoug.zmui3demo.ui;

import android.os.Bundle;
import android.view.View;

import com.zhoug.common3.adapters.recycler.BaseRecyclerViewAdapter;
import com.zhoug.common3.adapters.recycler.TextAdapter;
import com.zhoug.common3.adapters.recycler.dividers.ListItemDecoration;
import com.zhoug.zmui3.dialog.ZMUITipDialog;
import com.zhoug.zmui3demo.R;

import java.util.Arrays;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.OrientationHelper;
import androidx.recyclerview.widget.RecyclerView;

public class ZmuiTipDialogActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;
    private List<String> data = Arrays.asList(
            "Loading类型的提示框",
            "成功提示框",
            "失败提示框",
            "信息提示框",
            "单独图片提示框",
            "单独文字提示框"
    );

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zmui_tip_dialog);
        findViews();

        TextAdapter<String> adapter = new TextAdapter<String>() {
            @Override
            public String getText(String s) {
                return s;
            }
        };
        adapter.setData(data);
        adapter.setOnItemClickListener(new BaseRecyclerViewAdapter.OnItemClickListener<String>() {
            @Override
            public void onItemClick(BaseRecyclerViewAdapter<String> adapter, View view, int position) {
                show(position);
            }
        });
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.addItemDecoration(new ListItemDecoration(this, OrientationHelper.VERTICAL));
        mRecyclerView.setAdapter(adapter);
    }

    private void findViews() {
        mRecyclerView = findViewById(R.id.recyclerView);
    }


    private void show(int position) {
        ZMUITipDialog tipDialog = new ZMUITipDialog(this);
        switch (position) {
            case 1://成功提示框
                tipDialog.setType(ZMUITipDialog.TYPE_SUCCESS);
                tipDialog.setInfo("加载成功");
                break;
            case 2://失败提示框
                tipDialog.setType(ZMUITipDialog.TYPE_ERROR);
                tipDialog.setInfo("加载失败");

                break;
            case 3://信息提示框
                tipDialog.setType(ZMUITipDialog.TYPE_INFO);
                tipDialog.setInfo("请勿重复操作");
                break;
            case 4://单独图片提示框
                tipDialog.setType(ZMUITipDialog.TYPE_SUCCESS);
                break;
            case 5://单独文字提示框
                tipDialog.setInfo("请勿重复操作");
                break;
            default://Loading类型的提示框
                tipDialog.setType(ZMUITipDialog.TYPE_LOADING);
                tipDialog.setInfo("正在加载");
                tipDialog.setAutoClose(false);
                mRecyclerView.postDelayed(tipDialog::dismiss, 3000);
                break;
        }
        tipDialog.setShowLength(ZMUITipDialog.SHOW_LENGTH_LONG);
        tipDialog.show();

    }
}